<template>
  <el-dialog :visible.sync="showDialog" width="770" :show-close="false">
    <div class="roleBox">
      <el-transfer
        filterable
        :filter-method="filterMethod"
        :titles="['人员列表', '已选人员']"
        filter-placeholder="请输入名称"
        v-model="value"
        :data="data"
      >
      </el-transfer>
      <div class="btn">
        <button @click="cancel">取消</button>
        <button @click="sendRoleList">确定</button>
      </div>
    </div>
  </el-dialog>
</template>

<script>
export default {
  props: {
    showDialog: {
      type: Boolean,
      required: true
    },
    selectUserByDepartmentId: {
      type: [Object, Array],
      required: true
    } // 数据列表
  },
  data() {
    const generateData = _ => {
      const data = [];
      const cities = ['上海', '北京', '广州', '深圳', '南京', '西安', '成都'];
      const pinyin = ['上海', '北京', '广州', '深圳', '南京', '西安', '成都'];
      // const cities = [...this.selectUserByDepartmentId.teacherList, ...this.selectUserByDepartmentId.studentList];
      // const pinyin = [...this.selectUserByDepartmentId.teacherList, ...this.selectUserByDepartmentId.studentList];
      cities.forEach((city, index) => {
        data.push({
          label: city,
          key: index,
          pinyin: pinyin[index]
        });
      });
      return data;
    };
    return {
      data: generateData(),
      // data: [...this.selectUserByDepartmentId.teacherList, ...this.selectUserByDepartmentId.studentList],
      value: [],
      filterMethod(query, item) {
        return item.pinyin.indexOf(query) > -1;
      }
    };
  },
  created() {
    console.log(this.data);
  },
  methods: {
    // 确定按钮
    sendRoleList() {
      console.log(this.data);
      console.log(this.value);
    },
    // 取消按钮
    cancel() {
      // 关闭对话框
      this.$emit('update:showDialog', false);
    }
  }
};
</script>

<style scoped lang="less">
button {
  cursor: pointer;
}
/deep/.el-dialog__header,
/deep/.el-dialog__body {
  padding: 0;
}
/deep/.el-dialog {
  box-shadow: 3px 3px 11px 0px #3d3d3d;
}
/deep/ .el-transfer-panel {
  width: 39%;
  height: 50vh;
}
/deep/ .el-transfer__buttons {
  width: calc(22% - 60px);
}
.roleBox {
  padding: 30px;
  .btn {
    text-align: center;
    margin-top: 36px;
    padding-bottom: 10px;
    button {
      width: 100px;
      height: 35px;
      background: #e8f8fb;
      border-radius: 4px;
      margin: 0px 42px;
      color: #2fc0e0;
      &:nth-child(2) {
        background: #2fc0e0;
        color: white;
      }
    }
  }
}
</style>
